<?php


namespace app\api\controller;


use app\api\validate\UserValidate;
use app\api\model\UserModel;
use app\BaseController;
use think\Request;

class User extends BaseController
{
    public function index(Request $request)
    {
        $data = $request->param();
        //验证器
        $validate = new UserValidate();
        $val = $validate->scene('register')->check($data);
        if(!$val)
        {
            return error($validate->getError());
        }
        //密码加密
        $str = createRandStr();
        $data['salt'] = $str;
        $data['password'] = md5($data['password'].$str);
        //入库
        $res = UserModel::create($data);
        if($res)
        {
            return success('注册成功');
        }else{
            return error('注册失败');
        }
    }
}